﻿using System;
using System.Globalization;
using System.Windows.Data;
namespace CoreModule.Converters
{
    /// <summary>
    /// 身份证 加Mask 处理
    /// </summary>
    public class IdCardBirthDateMaskConverter : IValueConverter
    {
        /// <summary>
        /// 
        /// </summary>
        public string BirthDateMask_15{ get; set; } = "******";
        public string BirthDateMask_18 { get; set; } = "********";
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return "-";
            }
            if (value is string)
            {
                var str = value as string;
                if (str.Length ==15)
                {
                    return  str.Substring(0, 6) + BirthDateMask_15 + str.Substring(12, 3);
                }
                else if (str.Length >= 18)
                {
                    return str.Substring(0, 6) + BirthDateMask_18 + str.Substring(14, 4);
                }
            }
            return "-";
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
